#ifndef __DRV_l2_SPI_FLASH_H__
#define __DRV_l2_SPI_FLASH_H__

#include "driver_l2.h"

extern float UPGRADE_BIN_SIZE;		//means the "gp_cardvr_upgrade.bin" total size	 (unit KB)
extern float OVER_PROVISIONING;	//means reserve some space, In case the gp_cardvr_upgrade.bin is too large (unit KB)
extern float SPI_FLASH_TOTAL_SIZE;	//means the capacity of the SPI FLASH CHIP (unit MB)
extern INT32U CLOCK_SPEED;

// The spi flash is connect to spi 0
#if 0//C_SPI_FLASH_DISK
#define C_SPI_NUM					SPI_0			// use spi 0
#define C_SPI_CS_PIN				48   //IOD0:48   IOD6:54
#else
#define C_SPI_NUM			SPI_1	// use spi 1
#define C_SPI_CS_PIN		58		//IOC8:40   IOD10:58
#endif

#define C_SPI_TIME_OUT		3000	// time out count
#define SPI_FLASH_BUSY		- 1
#define SPI_FLASH_TIMEOUT	- 2

#define SPI_FLASH_SR_WIP	0x01

extern INT32S	SPI_Flash_init(void);

// byte 1 is manufacturer ID,byte 2 is memory type ID ,byte 3 is device ID
extern INT32S	SPI_Flash_readID(INT8U *Id);

// sector earse(4k byte)
extern INT32S	SPI_Flash_erase_sector(INT32U addr);

// block erase(64k byte)
extern INT32S	SPI_Flash_erase_block(INT32U addr);

// chip erase
extern INT32S	SPI_Flash_erase_chip(void);

// read a page(256 byte)
extern INT32S	SPI_Flash_read_page(INT32U addr, INT8U *buf);

// write a page(256 byte)
extern INT32S	SPI_Flash_write_page(INT32U addr, INT8U *buf);

// read n byte
extern INT32S	SPI_Flash_read(INT32U addr, INT8U *buf, INT32U nByte);

extern void		SPI_LOCK(void);
extern void		SPI_UNLOCK(void);




#endif /*__drv_l1_SENSOR_H__*/
